package com.gxkj.movie.controllers;

import com.gxkj.movie.controllers.seo.IndexSeo;
import com.gxkj.movie.helpers.BaiduSpiderHelper;
import com.gxkj.movie.threads.BaiduSubmitUrlThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @author sqyc
 */
@Controller
@Slf4j
public class GxzwController extends BaseController {


    @Autowired
    private BaiduSpiderHelper baiduSpiderHelper;


    @GetMapping("gxzw")
    public String index(HttpServletRequest req, Model model,@RequestParam(value = "forceclear" ,required=false,defaultValue ="false") Boolean forceclear){



        String basePath = req.getScheme()+"://"+req.getServerName()+"/gxzw";

        String[] param = {
                //需要推送的网址
                basePath
        };

        new Thread(new BaiduSubmitUrlThread(baiduSpiderHelper,param)).start();

        clckTime ++;
        cacheContol(req,model,forceclear);
        renderHeader(  req,   model);
        return getTempletate(req)+"/gxzw";
    }


    @Override
    public void renderHeader(HttpServletRequest req, Model model){
        super.renderHeader(req,model);
        model.addAttribute("menu", MenuEnum.GXZW.getKey());
        model.addAttribute("TITLE", IndexSeo.TITLE);
        model.addAttribute("KEYWORDS",IndexSeo.KEYWORDS);
        model.addAttribute("DESCRIPTION",IndexSeo.DESCRIPTION);
        model.addAttribute("SITE_NAME", IndexSeo.SITE_NAME);
    }





}
